using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BLL;
using Table_Dal;
namespace ApplicationLayer.ThiSinh
{
    public partial class frmThemTS_DeThi : DevComponents.DotNetBar.OfficeForm
    {
        List<string> lstMa = null;
        string Made = "";
        public frmThemTS_DeThi(List<string>ds,string ma)
        {
            lstMa = ds;
            Made = ma;
            InitializeComponent();
        }
        public bool KiemTra(string k)
        {
            foreach (string item in lstMa)
            {
                if (item.Equals(k) == true)
                    return true;
            }
            return false;
        }
        private void frmThemTS_DeThi_Load(object sender, EventArgs e)
        {
            ThiSinhBLL tsbll = new ThiSinhBLL();
            List<ThiSinhTbl> list = tsbll.LayTatCaThiSinh();
            List<ThiSinhTbl> dsnew= new List<ThiSinhTbl>();
            foreach (ThiSinhTbl item in list)
            {
                if (KiemTra(item.MSSV) == false)
                {

                    dsnew.Add(item);
                }
            }
            dgvThiSinh.Columns[1].ReadOnly = true;

            dgvThiSinh.DataSource = dsnew;
            dgvThiSinh.Columns["MATKHAU"].Visible = false;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DiemBLL d = new DiemBLL();
            int k = 0;
            for (int i = 0; i < dgvThiSinh.Rows.Count ; i++)
            {
                if (dgvThiSinh.Rows[i].Cells[0].Value != null)
                {
                    if ((bool)dgvThiSinh.Rows[i].Cells[0].Value == true)
                    {
                    DiemTbl dtbl = new DiemTbl();
                    dtbl.MSSV = dgvThiSinh.Rows[i].Cells[1].Value.ToString();
                    dtbl.MaDeThi = Made;
                    d.Them(dtbl);
                    k = 1;
                    }
                }
            }
            if(k==1)
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            else this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void btnKhongchon_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgvThiSinh.Rows.Count; i++)
            {
                dgvThiSinh.Rows[i].Cells[0].Value = null;
            }
        }

        private void btnChonHet_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgvThiSinh.Rows.Count; i++)
            {
                dgvThiSinh.Rows[i].Cells[0].Value = true;
            }
        }
    }
}